from SerialDeviceControl import serialPortTool
from SerialDeviceControl import FixSerialPortTool
from EthDeviceControl import EthernetPortTool
from FileControl import fileOperate
from time import sleep
import time

EnablePrintDebugInfo = 1



serialtool_COM5 = FixSerialPortTool("COM147",EnablePrintDebugInfo)
serialtool_COM6 = FixSerialPortTool("COM148",EnablePrintDebugInfo)
serialtool_COM5.SerialPortopen()
serialtool_COM5.SerialPortWrite("P 5")
sleep(0.5)
print serialtool_COM5.SerialPortRead(6)

serialtool_COM6.SerialPortopen()
serialtool_COM6.SerialPortWrite("P 5")
sleep(0.5)
#s = serialtool.SerialPortRead(6)

print serialtool_COM6.SerialPortRead(6)




'''
serialtool = serialPortTool("USB VID:PID=2886:8030",EnablePrintDebugInfo)
#k34461a = EthernetPortTool("192.168.237.199",5025,EnablePrintDebugInfo)

serialtool.find_SerialPort()
serialtool.SerialPortopen()
serialtool.SerialPortWrite("P 5")
sleep(0.5)
s = serialtool.SerialPortRead(6)
print s

k34461a.ConnectEthDevice()
while True:
    k34461a.Keysight34461ARangeSet("C0.1")
    sleep(1)
    k34461a.Keysight34461ARangeSet("C1")
    sleep(1)
    k34461a.Keysight34461ARangeSet("C3")
    sleep(1)
    k34461a.Keysight34461AMeas()
    s = k34461a.EthDeviceReceive()
    print s


s1 = "helloWorld this is a good day\n"
s2 = "Happy birthday to you, this a good day\n"
gain = 1
tmp = 20

currentTime = time.strftime("T%Y%m%d-%H%M%S",time.localtime())
fileName = currentTime.strip("\r\n") + "_#20" + "_gain" + str(gain) + "_tmp" + str(tmp) + ".txt"

fileName = "T20201219-113040_#20_gain1_tmp20.txt"
filePath = "./ref_2.5/"


logFile = fileOperate(filePath,fileName,EnablePrintDebugInfo)
logFile.creatFileObjectWrite()
logFile.fileWrite(s1)
logFile.fileWrite(s2)
logFile.fileWrite(s2)
logFile.fileWrite(s2)
logFile.fileWrite(s1)
logFile.fileClose()

logFileRead = fileOperate(filePath,fileName,EnablePrintDebugInfo)
logFileRead.creatFileObjectRead()
s = logFileRead.fileRead()
logFile.fileClose()
print s
'''

